/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.db.sql;

import de.mnit.basis.db.zugang.S_DBZugang;
import de.mnit.basis.fehler.Fehler;
import de.mnit.basis.sys.datei.S_Datei;

/**
 * @author Michael Nitsche
 */
public class HSQLDB extends A_SqlDB {

	public HSQLDB(S_DBZugang dbz)                                  	{ super(dbz.gHost(), dbz.gDB(), dbz.gUser(), dbz.gPass(), false); } //Mem
	public HSQLDB()                                                 { super("", "", "sa", "", false); } //Mem
	public HSQLDB(String datei)                                     { super("", datei, "sa", "", false); } //File
	public HSQLDB(S_Datei datei)                                    { super("", datei.gPfadKomplett(), "sa", "", false); } //File
	public HSQLDB(String host, String db, String user, String pass)	{ super(host, db, user, pass, false); }


	protected void erstelle(String host, String db, String user, String pass) {
		Fehler.sonstige.da_ToDo();
	}

	protected String jdbc(String host, String db) {
		// Shutdown=true greift nur, wenn die connection richtig geschlossen wird
//		a connection property, shutdown=true, can be specified on the first connection to the database (the connection that opens the database) to force a shutdown when the last connection closes.
//		String url="jdbc:hsqldb:file:/tmp/hsql/db3";//	: File-persistence
//		String url="jdbc:hsqldb:hsql:DB_NAME";//		: database server
//		String url="jdbc:hsqldb:hsql://localhost/xdb"
//		String url="jdbc:hsqldb:mem:DBname";//			: in-memory only
//		hsqls = mit TLS
//		http, https = Webserver
//		res = Zugriff auf Jar
//		http://hsqldb.org/doc/src/org/hsqldb/jdbc/jdbcConnection.html
//		http://hsqldb.org/doc/guide/ch04.html

		// InMemory
		if(db==null || db.length()==0)
			return "jdbc:hsqldb:mem:memdb";

		// Server
		if(host!=null && host.length()>0)
			return "jdbc:hsqldb:hsql://"+host+"/"+db+";shutdown=true";

		return "jdbc:hsqldb:file:"+db+";shutdown=true";
	}

	protected String treiber() {
		return "org.hsqldb.jdbcDriver";
	}

}
